package com.by.charpter04.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.by.charpter04.R;
import com.by.charpter04.animate.MyActivity;

public class MyView extends View {


    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint  = new Paint();
        paint.setColor(Color.RED);
        Rect r = new Rect(40,40,200,100);
        canvas.drawRect(r,paint);
        paint.setTextSize(90);
        canvas.drawText("hello",40,200,paint);
        Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.bird_eight);
        canvas.drawBitmap(b,40,300,paint);

        Matrix matrix = new Matrix(); //创建一个矩阵
        matrix.setTranslate(100,100); //将矩阵向右（X轴）平移100，向下（Y轴）平移100
        canvas.drawBitmap(b, matrix, paint);//将图片按照矩阵的位置绘制到界面上
    }


}
